<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head>
	<th:block th:include="include :: header('泵站详情')" />
</head>
<body>
    <div class="container-div">
    <input name="stationId" autocomplete="off" id="psId"  class="form-control" type="hidden" th:value="${pumpStationInfo.id}" >
    	<div class="row">
    		 <div th:include="biz/pumpStation/include::detail-header"></div> 
    		<div class="col-sm-12">
		    	<div class="btn-group-sm" id="toolbar" role="group">
					 <a class="btn btn-success" onclick="addAlerm()" shiro:hasPermission="biz:alerm:setAdd">
						<i class="fa fa-plus"></i> 添加泵站告警设置
					</a> 
				</div>
				<table id="alerm-table" data-mobile-responsive="true"></table>
    		</div>
    	</div>
	</div>
    <div th:include="include::footer"></div>
    <script th:inline="javascript">
	    var editFlag = [[${@permission.hasPermi('biz:alerm:setEdit')}]];
	    var removeFlag = [[${@permission.hasPermi('biz:alerm:setRemove')}]];
	    var types = [[${@dict.getType('biz_is_valid')}]];
	    var datas = [[${@dict.getType('biz_is_delete')}]];
	    var isMutes =  [[${@dict.getType('biz_is_mute')}]];
	    var jcptypes = [[${@dict.getType('biz_alerm_config_type')}]];
	    var fieldTypes = [[${@dict.getType('biz_alerm_field_type')}]];
	    var prefix = ctx + "biz/alerm";
        
        function addAlerm(){
        	var url = prefix + "/config/add?stationId="+[[${pumpStationInfo.id}]]+"&stationName="+[[${pumpStationInfo.name}]];
        	$.modal.open('添加告警设置', url);
        }
        
        
        $(function() {
            var options = {
            	id: "alerm-table",
                url: prefix + "/config/detailList?stationId="+[[${pumpStationInfo.id}]],
                //createUrl: prefix + "/config/add",
                updateUrl: prefix + "/config/edit/{id}",
                removeUrl: prefix + "/config/remove",
                modalName: "告警设置",
                columns: [
				{
					field : 'id', 
					title : 'ID' 
				},
				/* {
					field : 'stationName', 
					title : '泵站名称' 
				}, */
		        {
		            field: 'type',
		            title: '类型',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	return $.table.selectDictLabel(jcptypes, value);
		            }
		        },
		        {
		            field: 'fieldType',
		            title: '属性类型',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	return $.table.selectDictLabel(fieldTypes, value);
		            }
		        },
		        {
					field : 'highThreshold', 
					title : '高阈值' 
				},
				{
					field : 'lowThreshold', 
					title : '低阈值' 
				},
				{
		            field: 'isMute',
		            title: '是否静音',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	return $.table.selectDictLabel(isMutes, value);
		            }
		        },
				{
		            field: 'isValid',
		            title: '是否有效',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	return statusTools(row);
		            }
		        },
				/* {
		            field: 'isDeleted',
		            title: '是否删除',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	return $.table.selectDictLabel(datas, value);
		            }
		        }, */
				{
					field : 'createBy', 
					title : '创建者' 
				},
				{
		            field: 'createTime',
		            title: '创建时间',
		            sortable: false
		        },
		        {
		            field: 'remark',
		            title: '备注'
		        },
		        /* {
					field : 'updateBy', 
					title : '更新者' 
				},
				{
		            field: 'updateTime',
		            title: '更新时间',
		            sortable: true
		        }, */
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
        
        function statusTools(row) {
		    if (row.isValid == 0) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
    		}
		}
		
		function disable(id) {
			$.modal.confirm("确认要失效吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 0 });
		    })
		}

		function enable(id) {
			$.modal.confirm("确认要启用吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 });
		    })
		}
        
    </script>
</body>
</html>
